/**
 * Created by zby on 2018/5/3.
 */

import java.util.*;

class StudentKey implements Comparable {
    double d = 0;
    String s = "";

    StudentKey(double d) {
        this.d = d;
    }

    StudentKey(String s) {
        this.s = s;
    }

    public int compareTo(Object b) {
        StudentKey st = (StudentKey) b;
        if ((this.d - st.d) == 0)
            return -1;
        else
            return (int) ((this.d - st.d) * 1000);
    }
}

class StudentIF {
    String name = null;
    double math, english, computer, total, aver;

    StudentIF(String s, double m, double e, double f, double a, double b) {
        name = s;
        math = m;
        english = e;
        computer = f;
        total = a;
        aver = b;
    }
}

public class StudentClass {
    public static void main(String args[]) {
        TreeMap<StudentKey, StudentIF> treemap = new TreeMap<StudentKey, StudentIF>();
        String str[] = {"陈厚康", "叶佺", "赵冰雨", "王彦博", "葛宇豪"};
        double math[] = {88, 45, 87, 76, 70};
        double english[] = {67, 68, 69, 70, 79};
        double computer[] = {77, 100, 76, 65, 80};
        double total[] = new double[5];
        double aver[] = new double[5];
        StudentIF student[] = new StudentIF[5];
        for (int k = 0; k < student.length; k++) {
            total[k] = math[k] + english[k] + computer[k];
            aver[k] = total[k] / 3;
        }
        for (int k = 0; k < student.length; k++) {
            student[k] = new StudentIF(str[k], math[k], english[k], computer[k], total[k], aver[k]);
        }
        StudentKey key[] = new StudentKey[5];
        for (int k = 0; k < key.length; k++) {
            key[k] = new StudentKey(student[k].total);
        }
        for (int k = 0; k < student.length; k++) {
            treemap.put(key[k], student[k]);
        }
        int number = treemap.size();
        //System.out.println("树映射中有" + number + "个对象,按总成绩排序:");
        Collection<StudentIF> collection = treemap.values();
        Iterator<StudentIF> iter = collection.iterator();
        while (iter.hasNext()) {
            StudentIF stu = iter.next();
            System.out.println("姓名： " + stu.name + " 总成绩： " + stu.total);
        }
    }
}
